package cn.izeno.wx.models

import org.dom4j.Document

/**
 * <h1>微信公众号事件消息</h1>
 *
 * @author 陈治谋 (chenzhimou@tele-sing.com)
 */
class EventMessage : Message(msgType = MSG_TYPE_EVENT) {
  var event: String? = null
  var eventKey: String? = null
  var ticket: String? = null

  override fun parseXML(document: Document) {
    super.parseXML(document)

    val event = document.selectSingleNode("/xml/Event")
    if (null != event)
      this.event = event.text

    val eventKey = document.selectSingleNode("/xml/EventKey")
    if (null != eventKey)
      this.eventKey = eventKey.text

    val ticket = document.selectSingleNode("/xml/Ticket")
    if (null != ticket)
      this.ticket = ticket.text
  }

  override fun toXMLString(): String {
    TODO("not implement")
  }

  companion object {
    const val EVENT_SUBSCRIBE = "subscribe"       //关注
    const val EVENT_UNSUBSCRIBE = "unsubscribe"   //取关
    const val EVENT_SCAN = "SCAN"                 //扫描二维码
  }
}
